//导入http模块
const http = require('http');
//创建服务对象
const server = http.createServer((req, res) => {
    //设置文本格式utf-8
    res.setHeader('content-type', 'text/html;charset=utf-8')
    // 获取请求的方法
    let {method} = req;
    // 获取请求的url路径
    let {pathname} = new URL(req.url, 'http://127.0.0.1')
    // console.log('请求方法：' + method)
    // console.log('请求路径：' + pathname)

    // 判断
    if (method === 'GET' && pathname === '/login') {
        //登录的情形
        res.end('WellCome to login！！')
    } else if (method === 'GET' && pathname === '/reg') {
        // 注册的情形
        res.end('WellCome to register！！')
    } else {
        // 设置响应状态码404
        res.statusCode = 404;
        // 设置响应状态描述
        res.statusMessage='error'

        res.end('Not Found!!')
    }
});
// 启动服务
server.listen(9000, () => {
    console.log("The service has already been opened!!!")
})